<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link rel="stylesheet" th:href="@{/Bootstrapfileinput/css/theme.min.css}" />
<link rel="stylesheet" th:href="@{/Bootstrapfileinput/css/fileinput.min.css}" />
<link th:href="@{/ajax/libs/jquery-layout/jquery.layout-latest.css}" rel="stylesheet"/>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-wechatIndexPic-add">
			<div class="form-group">	
				<label class="col-sm-3 control-label">标题：</label>
				<div class="col-sm-8">
					<input id="title" name="title" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">子标题：</label>
				<div class="col-sm-8">
					<input id="subTitle" name="subTitle" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">图片：</label>
				<div class="col-sm-8">
					<input id="linkUrl" name="linkUrl" class="form-control" type="hidden">
					<input id="kv-explorer"  type="file" data-overwrite-initial="false"> <br>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">链接类型 ：</label>
				<div class="col-sm-8">
					<select id="linkType" name="linkType"  class="form-control" th:with="type=${@dict.getType('wechat_index_pic_type')}">
					  <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}">
					  </option>
					</select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label"> 图片的状态</label>
				<div class="col-sm-8">
					<select id="status" name="status"  class="form-control" th:with="type=${@dict.getType('wechat_index_pic_status')}">
					  <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}">
					  </option>
					</select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">排序：</label>
				<div class="col-sm-8">
					<input id="pos" name="pos" class="form-control" type="text">
				</div>
			</div>
		</form>
	</div>
    <script type="text/javascript" th:src="@{/Bootstrapfileinput/js/jquery-3.2.1.js}"></script>
	<script type="text/javascript" th:src="@{/Bootstrapfileinput/js/bootstrap.min.js}"></script>
	<script type="text/javascript" th:src="@{/Bootstrapfileinput/js/sortable.js}"></script>
	<script type="text/javascript" th:src="@{/Bootstrapfileinput/js/fileinput.min.js}"></script>
	<script type="text/javascript" th:src="@{/Bootstrapfileinput/js/theme.min.js}"></script>
	<script type="text/javascript" th:src="@{/Bootstrapfileinput/js/zh.js}"></script>
	<script th:src="@{/yiran/js/ry-ui.js?v=1.0}"></script>
	<script th:src="@{/ajax/libs/layer/layer.min.js}"></script>
	<script th:src="@{/ajax/libs/layui/layui.js}"></script>
	<script th:src="@{/ajax/libs/blockUI/jquery.blockUI.js}"></script>
	<script th:src="@{/ajax/libs/validate/jquery.validate.min.js}"></script>
	<script th:src="@{/yiran/js/common.js}"></script>
	<script th:inline="javascript"> var ctx = [[@{/}]]; </script>
    <script type="text/javascript">
		var prefix = ctx + "wechat/wechatIndexPic"
		$(function () {
			 $("#kv-explorer").fileinput({
				language: 'zh',
				//'theme': 'explorer',	//文件展示的主题风格
				'uploadUrl': ctx + "file/fileInfo/uploadImage",
				showRemove:false,
				showUpload: true, //是否显示上传按钮
				initialPreviewAsData: true,
				showCaption : false,//是否显示标题,就是那个文本框
				previewFileType:['image'],
				allowedFileExtensions:  ['jpg','png'],
				enctype:'multipart/form-data',
				showCancel:false,
				overwriteInitial:true, //不覆盖已存在的图片
				previewFileIcon: "<iclass='glyphicon glyphicon-king'></i>",
				msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
				dropZoneEnabled : true,//是否显示拖拽区域，默认不写为true，但是会占用很大区域
			    maxFileCount : 1, //表示允许同时上传的最大文件个数
			    validateInitialCount:true,
			   /*  minImageWidth: 550, //图片的最小宽度
			    minImageHeight: 280,//图片的最小高度
			    maxImageWidth: 650,//图片的最大宽度
			    maxImageHeight: 300,//图片的最大高度 */
				layoutTemplates:{
					actionUpload:'',//除去上传按预览缩略图中上传图标
				},
				dropZoneTitle: "上传图片640 * 300分辨率效果更好",
				previewSettings: {
		            image: {width: "630px", height: "250px"},
		        },
			 	uploadExtraData:function(){//向后台传递参数
	             	return { };
			 	}
			});

			//这是提交完成后的回调函数  
			 $("#kv-explorer").on("fileuploaded", function (event, data, previewId, index) {
				console.log('文件上传结果:'+data.response.result);
				console.log('文件上传信息:'+data.response.msg);
				console.log('文件上传路径:'+data.response.obj);
				if(data.response.result == 1){//成功
					$("#linkUrl").val(data.response.obj);
					//重新刷新页面
					//$.modal.msgReload("文件上传成功！","success");
				}else if(data.response.result == 0){
					
					$(event.target)
		              .fileinput('clear')
		              .fileinput('unlock');
		            $(event.target)
		              .parent()
		              .siblings('.fileinput-remove')
		              .hide();
		              $.modal.alertError("文件上传失败！");
				}
			 });
			
		 });
		
		function submitHandler() {
			var iconPath = $("#linkUrl").val();
			if(iconPath === ""){
				 $.modal.alertError("请先上传图片");
				return false;
			}
	        $.operate.save(prefix + "/add", $('#form-wechatIndexPic-add').serialize());
	    }
	</script>
</body>
</html>
